const { toUrl,globalData,msgLoading } = getApp();
import { request } from "@/utils/request";
Page({
  toUrl,
  msgLoading,
  data: {
    globalData,
    menu: 0,
    pages: 1,
    opderList: [],
    type: 0,
    isExit: false,
    count: null,
  },
  getOrder() {
    if (this.data.pages > 1 && this.data.pages > this.data.count) {
      this.setData({
        isExit: true,
      });
      return;
    }
    const that = this;
    const data = {
      typeid: this.data.type,
      page: this.data.pages,
    };
    request("order/orderlist", { data }).then((res) => {
      if (res.errcode == 1) {
        let pages = that.data.pages + 1;
        let list = this.data.opderList;
        if (that.data.pages > 1) {
          res.data.forEach((it, idx) => {
            list.push(it);
          });
          that.setData({
            opderList: list,
            pages,
            count: res.count,
          });
        } else {
          that.setData({
            opderList: res.data,
            pages,
            count: res.count,
          });
        }
      }
    }).finally(()=>{
      wx.hideLoading()
    })
  },

  types(data) {
    let { type } = data.currentTarget.dataset;
    let pages = 1;
    this.setData({
      type: type,
      pages,
      count:1,
      isExit:false
    });
    msgLoading()
    this.getOrder();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.showLoading({
      title: '加载中'
  })
    this.setData({
      type: options.type,
    });
    setTimeout(() => {
      wx.hideLoading()
  }, 500);
    // this.getOrder();
  },
  onShow() {
    this.setData({
      pages:1,
    })
    this.getOrder()
  },

  onReachBottom() {
    let isExit = this.data.isExit;
    if (isExit) {
      return;
    } else {
      this.getOrder();
    }
  },

});
